function findSmallClass(){
	var bigClass=$("#bigClass").val();
	if(bigClass==0){
		alert("请选择");
		var a="<option selected = \"selected\"  value='"+0+"'>先在这里选择二级分类</option>";
		$("#smallClass").html(a);
	}else{
		$.post("findbigClass.do?type="+2+'&bigClass='+bigClass,function(data){
			var a="<option selected = \"selected\"  value='"+0+"'>先在这里选择二级分类</option>";
			for (var i = 0; i < data.data.length; i++) {
				a+="<option  value="+data.data[i].cId+">"+data.data[i].cName+"</option>";
			}
			$("#smallClass").html(a);
		},"json")
	}

}
function findSubClass(){
 	var smallClass=$("#smallClass").val();
 	 $("#Parentlevelid").val(smallClass);
	layui.use('table', function(){
		  var table = layui.table;
		  table.reload('test', {
			  where: { //设定异步数据接口的额外参数，任意设
				  bigClass:smallClass
			  }
			  ,page: {
			    curr: 1 //重新从第 1 页开始
			  }
			}); 
})
}
$(function(){
	init();
})
function init(){
	layui.use('table', function(){
		  var table = layui.table;
		  table.render({
			  height: 20
		  });
	});	
}
function add(_this) {
	var tr      	 = $(_this).parents("tr");
	var names  		 = tr.find(".names").val();
	var fileupload    	 = tr.find(".fileupload").val();
	var Parentlevelid    	 = tr.find(".Parentlevelid").val();
	if(Parentlevelid==""||Parentlevelid==null){
		alert("请选择小类");
		return;
	}
	var type=3;
	var url     	 ="inserCateMange.do";
	$.ajax({
		url: url,
		type: 'post',
		dataType: 'json',
		data:{
			Parentlevelid:Parentlevelid,
			names: names,
			type: type,
			fileupload:fileupload,
		},
		success:function(res){
			if(res.type==1){
				layer.msg("添加成功！正在刷新页面...");
				setTimeout(function(){location.reload()}, 1000);
			}else{
				layer.msg("添加失败：");
				setTimeout(function(){location.reload()}, 1000);
			}
		}
	});
}
layui.use('upload', function(){
	  var $ = layui.jquery
	  ,upload = layui.upload;
	  
	  //普通图片上传
	  var uploadInst = upload.render({
	    elem: '#test1'
	    ,url: 'UploadServlet.do'
	    ,before: function(obj){
	      //预读本地文件示例，不支持ie8
	      obj.preview(function(index, file, result){
	        $('#demo1').attr('src', result); //图片链接（base64）
	      });
	    }
	    ,done: function(res){
	    	console.log(res);
	    	 if(res.type == 1){ //上传成功
	    		 var demoText = $('#demoText');
	    		  demoText.html('<span style="color: #FF5722;">上传成功</span>');
	    		  $("#fileupload").val(res.data.data.src);
	      }
	      //上传成功
	    }
	    ,error: function(){
	      //演示失败状态，并实现重传
	      var demoText = $('#demoText');
	      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
	      demoText.find('.demo-reload').on('click', function(){
	        uploadInst.upload();
	      });
	    }
	  });
	});
	function table(type,id,names){
		  if(type==0){
			  x_admin_show('修改','updateCateGory.do?type='+type+'&id='+id+'&names='+names+'&type2='+2,600,400)
		  }else{
			    layer.confirm("确认要删除吗，删除后不能恢复", { title: "删除确认" }, function (index) {
	              
	              $.post("delCid.do?id="+id, function (data) {
	              	if(data.type==1){
	              		layer.msg("操作成功");
	              		setTimeout(function(){
	                          //刷新
	                          location.reload();
	                      },1000);
	              	}else{
	              		layer.msg("操作失败");
	              		setTimeout(function(){
	                          //刷新
	                          location.reload();
	                      },1000);
	              	}

	              },"json");
	          }); 
		  }
	}
	$(function(){
		$.post("findbigClass.do?type="+1,function(data){
			var a="<option selected = \"selected\"  value='"+0+"'>先在这里选择大类</option>";;
			for (var i = 0; i < data.data.length; i++) {
				a+="<option  value="+data.data[i].cId+">"+data.data[i].cName+"</option>";
			}
			$("#bigClass").html(a);
		},"json")
	})